diff --git a/docs/8.-Shared-Token-Types.md b/docs/8.-Shared-Token-Types.md new file mode 100644 index 000000000..446786eff --- /dev/null +++ b/docs/8.-Shared-Token-Types.md @@ -0,0 +1,320 @@ +Shared token types enable comparisons between languages + +Examples are given in a pseudo language similar to Java or Cpp + +# The Imperative paradigm + +## Variables + +Variable definition: +``` +def x: Int +| VAR_DEF +``` + +Variable definition with assignment: +``` +def x: Int = 2 +| VAR_DEF + | ASSIGN +``` + +Assignment: +``` +x = 3 + | ASSIGN +``` + +## Types + +Structure definition: +``` +type Name { +| STRUCT_DEF + firstName: String + | STRUCT_MEMBER + lastName: String + | STRUCT_MEMBER +} +| STRUCT_END +``` + +## Control Structures + +If else: +``` +if (...) { +| IF +... +} else { + | ELSE +... +} +| IF_END +``` + +If without else: +``` +if(...) { +| IF +} +| IF_END +``` + +Switch-case: +``` +switch(...) { +| SWITCH + case a: { + | CASE + ... + } + | CASE_END + case b: { + | CASE + ... + } + | CASE_END +} +``` + +Switch-case with joined-cases (like in Java): +``` +switch(...) { +|SWITCH + case a: + | CASE + case b: { + | CASE + ... + } + | CASE_END +} +| SWITCH_END +``` + +Languages that require an explicit break to end the case clause should extract the CASE_END token on the break. + + + +While-loop: +``` +while(...) { +| LOOP + | + .... +} +| LOOP_END +``` + +For-loop: +``` +for(def x: Int = 0; x < y; x++) { +| LOOP + | + | VAR_DEF + | ASSIGN + ... + | +} +| LOOP_END +``` +The order of the tokens is the order of the lines here. It is intentionally different from the appearance in the code to be compatible to the while loop + +For-each: +``` +for i in { +| LOOP + | VAR_DEF + | + .... +} +| LOOP_END +``` + +Goto: +``` +goto