Skip to content

Commit

Permalink
fixes some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lrlucena committed Oct 7, 2023
1 parent 139ad83 commit 32f7bda
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
> A small programming language made with [Scala](https://scala-lang.org) and [ANTLR](https://antlr.org).
This is a simple programming language that has only one loop instruction (while) and a single type (integer).
We want to show that you can make a programming language with a only few lines of code.
We want to show how to implement a programming language with a few lines of code.

The language is implemented in two ways:
- as an [interpreter](interpreter.md)
- as a [transpiler](transpiler.md) (compiler) for Scala.
- as a [transpiler](transpiler.md) (compiler) to Scala.

<table>
<thead>
<tr>
<th> </th>
<th align="center">Interpreter</th>
<th align="center">Compiler (Transpiler)</th>
<th align="center">Transpiler (Compiler)</th>
</tr>
</thead>
<tbody>
Expand All @@ -40,7 +40,7 @@ The language is implemented in two ways:
<tr>
<th>Parser Rules</th>
<td colspan="2" align="center">
<a href="interpreter.md#parser-rules">Listener</a> (58 lines)
<a href="interpreter.md#parser-rules">Listener</a> (55 lines)
</td>
</tr>
<tr>
Expand All @@ -51,15 +51,15 @@ The language is implemented in two ways:
<tr>
<th>Utility Classes</th>
<td colspan="2" align="center">
<a href="interpreter.md#walker">Walker</a> (21 lines)<br>
<a href="interpreter.md#walker">Walker</a> (22 lines)<br>
<a href="interpreter.md#runner">Runner</a> (12 lines)<br>
<a href="interpreter.md#contextvalue">Runner</a> (9 lines)
<a href="interpreter.md#contextvalue">ContextValue</a> (12 lines)
</td>
</tr>
<tr>
<th>Total</th>
<td align="center">191 lines</td>
<td align="center">189 lines</td>
<td align="center">192 lines</td>
<td align="center">190 lines</td>
</tr>
</tbody>
</table>
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/whilelang/compiler/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package whilelang.compiler

import whilelang.util.Runner

@main def main = Runner:
program => println(program.meaning)
val action = Runner(program => println(program.meaning))

@main def main(file: String) = action(file)
5 changes: 3 additions & 2 deletions src/main/scala/whilelang/interpreter/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package whilelang.interpreter

import whilelang.util.Runner

@main def main = Runner:
program => program.execute()
val action = Runner(program => program.execute())

@main def main(file: String) = action(file)
10 changes: 4 additions & 6 deletions src/main/scala/whilelang/parser/MyListener.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MyListener extends BaseListener with ContextValue:
ctx.seqStatement.value

override def exitSeqStatement(ctx: SeqStatementContext): Unit = ctx.value_= :
SeqStatement(ctx.statement.map(_.value[Statement]))
SeqStatement(ctx.statement.map(_.value))

override def exitAttrib(ctx: AttribContext): Unit = ctx.value_= :
Attrib(ctx.ID.text, ctx.expression.value)
Expand Down Expand Up @@ -51,8 +51,7 @@ class MyListener extends BaseListener with ContextValue:
Integer(ctx.text.toInt)

override def exitBinOp(ctx: BinOpContext): Unit = ctx.value_= :
val lhs: Expression = ctx.expression(0).value
val rhs: Expression = ctx.expression(1).value
val Seq(lhs, rhs): Seq[Expression] = ctx.expression.map(_.value)
ctx(1).text match
case "*" => ExpMult(lhs, rhs)
case "-" => ExpSub(lhs, rhs)
Expand All @@ -71,8 +70,7 @@ class MyListener extends BaseListener with ContextValue:
ctx.bool.value

override def exitRelOp(ctx: RelOpContext): Unit = ctx.value_= :
val lhs: Expression = ctx.expression(0).value
val rhs: Expression = ctx.expression(1).value
val Seq(lhs, rhs): Seq[Expression] = ctx.expression.map(_.value)
ctx(1).text match
case "=" => ExpEq(lhs, rhs)
case "=" => ExpEq(lhs, rhs)
case "<=" | _ => ExpLe(lhs, rhs)

0 comments on commit 32f7bda

Please sign in to comment.