Mercurial > hg > graal-compiler
view graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/SimpleLanguage.atg @ 8988:02f57662b6c4
remove monitor limitation form TailDuplicationPhase
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Wed, 10 Apr 2013 15:57:30 +0200 |
parents | b6a87711eca0 |
children | 71991b7a0f14 |
line wrap: on
line source
COMPILER SimpleLanguage CHARACTERS letter = 'A'..'Z' + 'a'..'z'. nonZeroDigit = "123456789". digit = "0123456789". cr = '\r'. lf = '\n'. tab = '\t'. stringChar = ANY - "\"" - '\\' - cr - lf. TOKENS identifier = letter {letter | digit}. stringLiteral = "\"" { stringChar } "\"". numericLiteral = "0" | nonZeroDigit { digit }. PRAGMAS COMMENTS FROM "/*" TO "*/" COMMENTS FROM "//" TO lf IGNORE cr + lf + tab PRODUCTIONS SimpleLanguage = Function { Function } . Function = "function" (. factory.startFunction(); .) identifier (. String name = t.val; .) Block<out StatementNode body> (. factory.createFunction(body, name); .) . Block<out StatementNode result> = (. List<StatementNode> statements = new ArrayList<>(); .) "{" { Statement<out StatementNode statement> (. statements.add(statement); .) } "}" (. result = factory.createBlock(statements); .) . Statement<out StatementNode result> = (. result = null; .) ( WhileStatement<out result> | AssignmentStatement<out result> | OutputStatement<out result> | ReturnStatement<out result> ) . WhileStatement<out StatementNode result> = "while" "(" Expression<out ConditionNode condition> ")" Block<out StatementNode body> (. result = factory.createWhile(condition, body); .) . AssignmentStatement<out StatementNode result> = identifier (. String name = t.val; .) "=" Expression<out TypedNode rvalue> ";" (. result = factory.createAssignment(name, rvalue); .) . OutputStatement<out StatementNode result> = (. List<TypedNode> expressions = new ArrayList<>(); .) "print" { Expression<out TypedNode value> (. expressions.add(value); .) } ";" (. result = factory.createPrint(expressions); .) . ReturnStatement<out StatementNode result> = "return" Expression<out TypedNode value> ";" (. result = factory.createReturn(value); .) . Expression<out TypedNode result> = ValueExpression<out result> [ ("<" | ">" | "<=" | ">=" | "==" | "!=" ) (. String op = t.val; .) ValueExpression<out TypedNode right> (. result = factory.createBinary(op, result, right); .) ] . ValueExpression<out TypedNode result> = Term<out result> { ("+" | "-") (. String op = t.val; .) Term<out TypedNode right> (. result = factory.createBinary(op, result, right); .) } . Term<out TypedNode result> = Factor<out result> { ("*" | "/") (. String op = t.val; .) Factor<out TypedNode right> (. result = factory.createBinary(op, result, right); .) } . Factor<out TypedNode result> = (. result = null; .) ( TimeRef<out result> | VariableRef<out result> | StringLiteral<out result> | NumericLiteral<out result> | Ternary<out result> | "(" Expression<out result> ")" ) . Ternary<out TypedNode result> (. TypedNode condition, thenPart, elsePart; .) = "#" Expression<out condition> "?" Expression<out thenPart> ":" Expression<out elsePart> (. result = factory.createTernary(condition, thenPart, elsePart); .) . TimeRef<out TypedNode result> = "time" (. result = factory.createTime(); .) . VariableRef<out TypedNode result> = identifier (. result = factory.createLocal(t.val); .) . StringLiteral<out TypedNode result> = stringLiteral (. result = factory.createStringLiteral(t.val.substring(1, t.val.length() - 1)); .) . NumericLiteral<out TypedNode result> = numericLiteral (. result = factory.createNumericLiteral(t.val); .) . END SimpleLanguage.