Browse Source

Consider keeping operations but even more simplified, adding fields with selectors, and making blocks expressions as well.

Beoran 4 years ago
parent
commit
f70ae5b70f
1 changed files with 45 additions and 85 deletions
  1. 45 85
      parser.go

+ 45 - 85
parser.go

@@ -26,58 +26,53 @@ syntax, which has been verified to be LL(1) on smlweb.cpsc.ucalgary.ca. This
 means the parser only needs one token of lookahead to be able to parse the 
 syntax. The syntax can be described as follows:
 
-PROGRAM -> STATEMENTS .
-STATEMENTS -> STATEMENT STATEMENTS | .
-STATEMENT -> BLOCK | CHAIN eos | eos .
-CHAIN -> EXPRESSION OPERATIONS . 
-OPERATIONS -> LINK | .
-LINK -> OPERATION | REDIRECT | METHOD .
-METHOD -> method EXPRESSION . 
-REDIRECT -> redirect EXPRESSION . 
-OPERATION -> operator EXPRESSION .
-EXPRESSION -> COMMAND | SUBSTITUTION |  LITERAL .
-COMMAND -> NAME PARAMETERS.
-PARAMETERS -> PARAMETER PARAMETERS | .
-PARAMETER -> LITERAL | BLOCK |  SUBSTITUTION | NAME .
-SUBSTITUTION ->  GETTER | SETTER | LIST | PARENTHESIS .
-PARENTHESIS -> closeparen CHAIN openparen .
-BLOCK -> openblock STATEMENTS closeblock .
-LIST -> openlist PARAMETERS closelist .
-LITERAL -> string | int | float .
-NAME -> word | symbol | type .
-SETTER -> set PARAMETER PARAMETER . 
-GETTER -> get PARAMETER .
+PROGRAM -> STATEMENTS.
+STATEMENTS -> STATEMENT eos STATEMENTS|.
+STATEMENT -> EXPRESSION OPERATION |.
+OPERATION -> operator STATEMENT |.
+EXPRESSION -> COMMAND | EVALUATION.
+COMMAND -> FIELD PARAMETERS.
+FIELD -> NAME SELECTOR.
+SELECTOR -> selector PARAMETER |.
+PARAMETERS -> PARAMETER PARAMETERS |.
+PARAMETER -> FIELD | EVALUATION.
+EVALUATION ->  LITERAL | BLOCK | GETTER | SETTER | LIST | PARENTHESIS.
+PARENTHESIS -> closeparen STATEMENT openparen.
+BLOCK -> openblock STATEMENTS closeblock.
+LIST -> openlist PARAMETERS closelist.
+LITERAL -> string | int | float.
+NAME -> word | symbol | type.
+SETTER -> set PARAMETER PARAMETER.
+GETTER -> get PARAMETER.
+
 
 The semantics of a muesli program are based on this syntax and can be explained 
 as follows:
  
-- A muesli program consists of statements, which are executed from top to 
-  bottom.
-- A statement is either a block, or a command chain terminated by end of 
-  statement, eos,  or an empty statement terminated by eos. The period . and 
-  the unescaped newline characters are eos. 
-- A block consist of statements between braces { }. The statements of a block 
-  are not executed but compiled to a block which can be called to execute them
-  later.
-- A command chain consists of an expression optionally followed by links.
-  A command chain is executed by executing it's expression and applying the, 
-  operator, redirect and method links from left to right.
-- A link is either operator, redirect or method.
-- An operator begins with a token with one of the following characters: -+/*^%~
-  Next is an expression. The effect of an operator is to evaluate the 
+- A muesli program consists of statements, separated by end of statement or eos,  
+  which are executed from top to bottom. The period . and the unescaped newline 
+  characters are eos.
+- A statement an expression followed by an optional operation, or 
+  the empty statement. A statement evaluates to the value of it's expression
+  to which the consecutive operations are applied from right to left.
+- An expression is either a command or an evaluation.
+- An operation starts with an operator followed by a statement.
+  That statement may in turn contain another operation.
+- An operator begins with a token with one of the following characters: -+/*^%~|&><@
+  Next is a statement. The effect of an operator is to evaluate the 
   links before it and after it as a substitution, and then look up the callable
   with the name of the operator and execute that. 
-- A redirect starts with a token of the following characters: |&><@
-  Next is an expression. The effect of a redirect is to evaluate the 
-  links before it and after it as a block, and then look up the callable
-  with the name of the operator and execute that.
-- A method start with a token with one of the following characters: ,;
-  Next is an expression. The effect of a method is to evaluate the 
-  links before it and after it as a list of ast expressions, shuffle them 
-  so the operator comes first, but the rest is kept in order, and then look up 
-  the callable with the name of the operator and execute that.
-- A command may be a direct command, an indirect command, or a literal value.
-- A direct command  
+- A command consists of a field and parameters .  
+- A field is a name optionally followed by selectors .
+- An evaluation is a block, parenthesis, list, getter, setter, or literal.
+- A parameter is an evaluation or a field.
+- A selector starts with a token with one of the following characters: ,;'
+  Next is a parameter. The effect of a selector is to evaluate the
+  parameter, and then use it as a string to look up the value of the field
+  thus named in named object.
+- A block consist of statements between braces { }. The statements of a block 
+  are not executed but compiled to a block which can be called to execute it 
+  later.
 - A () parenthesis gets substituted inline by the value returned by executing it 
   anywhere it occurs, also in the beginning of a command.
 - A bracketed list [ elem1 elem2 ... ]  is syntactic sugar for (list elem1 elem 2)
@@ -85,45 +80,10 @@ as follows:
 - A equals setter =varname value is syntactic sugar for (set varname value)
 - Therefore, parenthesis, lists, getters and setters are allowed anywhere,
   also in the beginning of the command with substitution semantics.
-- If a command starts with a substitution, it is an indirect command. The
-  substitution is evaluated and it's value is looked up as the command name.
-  In case the result is not a name, this is a run time error.
-  In case the result is a list, each value of the list is executed as a command
-  with the same parameters.
-- A literal evaluate to itself.
-- A name also evaluates as itself but is specific for direct commands.
-
-
-Keeping operations, simplified, adding fields with selectors.
-
-PROGRAM -> STATEMENTS .
-STATEMENTS -> STATEMENT STATEMENTS | .
-STATEMENT -> BLOCK | CHAIN eos | eos .
-CHAIN -> EXPRESSION OPERATIONS . 
-OPERATIONS -> LINK | .
-LINK -> operator EXPRESSION .
-EXPRESSION -> COMMAND | SUBSTITUTION |  LITERAL .
-COMMAND -> FIELD PARAMETERS.
-FIELD -> NAME SELECTORS . 
-SELECTORS -> SELECTOR | .
-SELECTOR -> selector FIELD .
-PARAMETERS -> PARAMETER PARAMETERS | .
-PARAMETER -> LITERAL | BLOCK |  SUBSTITUTION | FIELD .
-SUBSTITUTION -> GETTER | SETTER | LIST | PARENTHESIS .
-PARENTHESIS -> closeparen CHAIN openparen .
-BLOCK -> openblock STATEMENTS closeblock .
-LIST -> openlist PARAMETERS closelist .
-LITERAL -> string | int | float .
-NAME -> word | symbol | type .
-SETTER -> set PARAMETER PARAMETER . 
-GETTER -> get PARAMETER .
-
-
- *
- * program -> statements
- * statements -> statement+
- * statement -> get / set / command
- *
+- A literal evaluates to itself.
+- A name also evaluates as itself but is specific for commands.
+
+
 */
 
 type Parser struct {