Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: March 28, 2024, 4:28 pm

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compiler Theory
#2
RE: Compiler Theory
(October 23, 2020 at 6:38 am)FlatAssembler Wrote: But it wasn't easy for me. Soon after starting learning ReactJS, I bumped into something like this:
Code:
const header=<h1>Hello world!</h1>;
I thought "Aha, that's some new syntax in JavaScript.". So I tried typing that into NodeJS, only to get a bunch of syntax errors. So I was thinking "What? If JavaScript engines can't parse the code when the ReactJS framework is not included, how can they possibly parse it when it is included? A framework can't possibly modify how the parser behaves, it starts executing only after the parsing phase has long passed. I don't get it.". Then came some importing CSS into JavaScript. I thought "What? How can that possibly work? JavaScript engines don't know anything about CSS. If you include a CSS file in JavaScript, it won't even tokenize (an identifier can't contain a '#' in JavaScript, but it can do so in CSS), yet alone parse and semantically analyze. I don't get it.". Then I saw the syntax for declaring properties of classes in JavaScript. In the example I saw, the declarations are separated with nothing but a new-line character. I thought: "What? But JavaScript is not a whitespace-sensitive language. How could this possibly work? How can the parser know where one declaration ends and where another declaration starts if they are not separated by a semicolon or a comma?". I thought it was too much for me, so I gave up.
So, maybe thinking about compiler theory is a very wrong way to think about the programming language you are studying. I was wondering what you thought about it.

That code was JSX, not Javascript.  It needs to be compiled by Babel into Javascript React.createElement() calls.

And, Javascript now has optional semicolons at the end of lines, in circumastances where the parser can figure out that the semicolon should've been there.  I think that's just lazy coding, but some people absolutely hate semicolons if they've never used a language that needs them (i.e. Python).

Real-world Javascript programs use a kitchen sink of tools these days.  It is the most confusing way to learn programming.
Reply



Messages In This Thread
Compiler Theory - by FlatAssembler - October 23, 2020 at 6:38 am
RE: Compiler Theory - by HappySkeptic - October 23, 2020 at 4:36 pm
RE: Compiler Theory - by FlatAssembler - October 24, 2020 at 4:20 am
RE: Compiler Theory - by HappySkeptic - October 26, 2020 at 11:18 am
RE: Compiler Theory - by FlatAssembler - October 26, 2020 at 3:40 pm
RE: Compiler Theory - by Angrboda - October 27, 2020 at 10:48 am

Possibly Related Threads...
Thread Author Replies Views Last Post
  Simulation Theory Foxaèr 12 963 October 3, 2021 at 1:58 pm
Last Post: Spongebob
  Arithmetic Expression Compiler FlatAssembler 69 8558 July 17, 2021 at 12:36 pm
Last Post: arewethereyet



Users browsing this thread: 1 Guest(s)